#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/time.h>
#include <stdint.h>

#include "icar.h"
#include "icar_msg.h"
#include "icar_log.h"
#include "icar_utils.h"
#include "icar_thread.h"

void
thread_flat(void *args)
{
	void **params;
	request *r;
	int fd;

	params = (void **)args;
	fd = *((int *)*params);
	r = *(params+1);
	free(params);


	if (icar_read_request(fd, r) == 0) {
		icar_daemon(LOG_DEBUG, "Process request from %s", r->clientAddr);
		icar_process_request(fd, r);
		icar_daemon(LOG_DEBUG, "Returned from icar_process_request() for %s", r->clientAddr);
	}

	icar_daemon(LOG_DEBUG, "No valid request received from %s", r->clientAddr);

	icar_end_request(r);
}
